#
#  octopus4r - a ruby wrapper for the Octopus USB board
#  Copyright (C) 2008 by Michael Conrad <do5mc@friggleware.de>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
#


require 'octopus_native'


module Octopus4r

  class I2C
    
    def intialize( device)
      @device = device.to_i
      @timeout = 500
        
      return
    end

    
    def init
      Octopus_native::octopus_i2c_init( @device)
    end

    
    def deinit
      Octopus_native::octopus_i2c_deinit( @device)
    end


    def bitrate=(bitrate)
      Octopus_native::octopus_i2c_set_bitrate( @device, bitrate.to_i)
    end


    def send_start
      Octopus_native::octopus_i2c_send_start( @device)
    end


    def send_stop
      Octopus_native::octopus_i2c_send_stop( @device)
    end


    def send_byte( data)
      Octopus_native::octopus_i2c_send_byte( data)
    end


    def send_bytes( data)
      Octopus_native::octopus_i2c_send_bytes( @device, data, data.length, @timeout)
    end


    def recv_byte( address)
      Octopus_native::octopus_i2c_recv_byte( @device, address.to_i, @timeout)
    end

    
    def recv_bytes( address, data)
      Octopus_native::octopus_i2c_recv_bytes( @device, address.to_i, data, data.lenth, @timeout)
    end


  end


end
